			<div>
				<ul class="breadcrumb">
					<li>
						<a href="<?php echo site_url("menu/survey"); ?>">Quản lý khảo sát</a> / 
						<a href="<?php echo site_url("surveytype"); ?>">Loại khảo sát</a> / 
						<a href="<?php echo site_url("survey/index/" . $st->survey_type_id); ?>"><?php echo $st->survey_type_name ?></a> / 
						<a href="<?php echo site_url("survey/details/" . $survey->survey_id); ?>"><?php echo $survey->survey_name ?></a> / 
						Sửa phiếu khảo sát
					</li>
				</ul>
			</div>
			<div class="row-fluid">
				<div class="box span12">
					<div class="box-header well">
						<h2><i class="icon-pencil"></i> Bước 4: Điều chỉnh</h2>
						<div class="box-icon">
							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						</div>
					</div>
					<div class="box-content">
                        <form method="post">
							<!--questions-->
                            <?php $i=0; $otype=null; foreach($qlist as $q){ ?>
							<div class="row-fluid">
								<div class="box span12">
									<div class="box-header well">
										<h3>
                                            Câu hỏi <?php echo $q->view_order.': '.$q->content; if($q->required){?>
                                            <span class="icon icon-red icon-star-on">
                                            <?php };?>
                                        </h3>
										<div class="box-icon">
											<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
										</div>
									</div>
									<div class="box-content">
                                        <?php foreach($atlist[$i] as $at){ $otype = $at->option_type;?>
    										<div class="controls">
                                                <?php if($at->option_type=='r '){ ?>
        											<label class="radio">
        												<input name="<?php echo $i; ?>" type="radio"/>
        												<?php echo $at->label; ?>
        											</label>
                                                <?php } else if($at->option_type=='c '){ ?>
        											<label class="checkbox">
        												<input type="checkbox"/>
        												<?php echo $at->label; ?>
        											</label>
                                                <?php } else if($at->option_type=='t '){ ?>
                                                    <?php echo $at->label; ?>
    											    <input type="text" class="span4"/>
                                                <?php } else if($at->option_type=='rt'){ ?>
        											<label class="radio">
        												<input name="<?php echo $i; ?>" type="radio"/>
        												<?php echo $at->label; ?>
        											</label>
                                                    <input type="text" class="span4"/>
                                                <?php } else if($at->option_type=='ct'){ ?>
                                                    <label class="checkbox">
        												<input type="checkbox"/>
        												<?php echo $at->label; ?>
        											</label>
    											    <input type="text" class="span4"/>
                                                <?php } else if($at->option_type=='pr'){ ?>
													<?php echo $at->label; ?>
													<div class="input-append">
														<input type="text" class="span4"/>
														<select>
														<?php foreach($prlist as $pr){ ?>
															<option><?php echo $pr->province_name;?></option>
														<?php };?>
														</select>
													</div>
                                                <?php }; ?>
    										</div>
                                        <?php };?>
										<div class="form-actions">
                                            <?php if($otype == 'r ' || $otype == 'rt'){ ?>
        										<label class="checkbox inline">
        											<input type="checkbox" divlink="#divlink<?php echo $i;?>" class="cblink" 
														<?php if($linklist[$i]) echo 'checked';?>
														qid="<?php echo $q->question_id;?>" sid="<?php echo $survey->survey_id;?>"/> 
													Tạo liên kết câu hỏi
        										</label>
                                            <?php }; ?>
    										<label class="checkbox inline">
    											<input type="checkbox" name="isvals[<?php echo $i;?>]" value="true" <?php if($q->is_validated == TRUE) echo 'checked';?>/> Thông tin cần cho xác thực
    										</label>
                                            <?php if($survey->is_evaluated == true){ ?>
        										<label class="checkbox inline">
        											<input type="checkbox" name="isevals[<?php echo $i;?>]" value="true" <?php if($q->is_evaluated == TRUE) echo 'checked';?>/> Thông tin cần cho đánh giá
        										</label>
                                            <?php }; ?>
                                            <?php if(($otype == 'r ' || $otype == 'rt') && $maxq > 1){ ?>
                                                <div id="divlink<?php echo $i;?>" <?php if(!$linklist[$i]) echo "style='display: none;'";?>>
                                                    <hr/>
													<?php $j=0; foreach($atlist[$i] as $at){?>
														<div class="control-group">
															<label class="control-label"><?php echo $at->label;?></label>
															<div class="controls">
																<?php for($k=0; $k<$maxq-$i-1; $k++){?>
																	<input type="checkbox" class="cbar"
																		<?php if(!$linklist[$i] || $arlist[$i][$j][$k]->attribute) echo 'checked';?>
																		atid="<?php echo $at->template_id;?>"
																		qid="<?php echo $qlist[$k+$i+1]->question_id;?>"/>Câu <?php echo $k+$i+2;?>
																<?php };?>
															</div>
														</div>
													<?php $j++; };?>
                                                </div>
                                            <?php }; ?>
										</div>
									</div>
								</div>
							</div>
                            <?php $i++; }; ?>
							<!--/questions-->
    						<div class="form-actions">
    							<button type="submit" name="submit" value="submit" class="btn btn-primary">Hoàn tất</button>
    							<a class="btn" href="<?php echo site_url("survey/edit_step3");?>">Quay lại bước 3</a>
    						</div>
                        </form>
					</div>
				</div><!--/span-->
		</div>
        <!-- Popup notify can't connect to server -->
		<div class="modal hide fade" id="errorModal">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">×</button>
					<h3>Error!!!</h3>
				</div>
    				<div class="modal-body">
    					<fieldset>
    						<div class="control-group">
                                Lỗi kết nối đến máy chủ.
    						</div>
    					</fieldset>
    				</div>
    				<div class="modal-footer">
    					<a href="#" class="btn" data-dismiss="modal">Thoát</a>
    				</div>
		</div>
    <!-- Placed at the end of the document so the pages load faster -->
    <!-- Internal Script -->
    <script type="text/javascript">
        $(document).ready(function(){
            //Event of isgraduated checkbox
            $('.cblink').change(function(){
				var val = $(this).is(':checked');
				var divlink = $(this).attr('divlink');
				var sid = $(this).attr('sid');
				var qid = $(this).attr('qid');
                if(val == true){
					$.get("<?php echo base_url();?>survey/add_answer_relations_list/" + sid + "/" + qid,function(data, result){
						if(result=='success')
							$(divlink).slideToggle();
						else
							$("#errorModal").modal('show');
					});
                }else{
					$.get("<?php echo base_url();?>survey/delete_answer_relations_list/" + qid,function(data, result){
						if(result=='success')
							$(divlink).slideToggle();
						else
							$("#errorModal").modal('show');
					});
				}
            });
			//Event of checkbox answer relation
            $('.cbar').change(function(){
				var atid = $(this).attr('atid');
				var qid = $(this).attr('qid');
				var attr = $(this).is(':checked');
                $.get("<?php echo base_url();?>survey/edit_answer_relation/" + atid + "/" + qid + "/" + attr,function(data, result){
					if(result!='success'){
						$("#errorModal").modal('show');
					}
				});
            });
        });
    </script>
    <!-- End Internal Script -->